package com.tsc.springTemp.annotation;

import java.lang.reflect.Field;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: chentl
 * @Date: 2025/09/14/15:56
 * @Description:
 */
public class Validator {

    public static void validate(Object obj) throws IllegalAccessException, ValidationException {
        Field[] fields = obj.getClass().getDeclaredFields();

        for (Field field : fields){
            field.setAccessible(true);
            NotNull notNull = field.getAnnotation(NotNull.class);

            if (field.isAnnotationPresent(NotNull.class)){

                Object value = field.get( obj);
                if (value instanceof String && ((String)value).isBlank()){
                    throw new ValidationException(notNull.message());
                }
            }
        }
    }
}
